<?php
namespace logic\sys\images;
use \OSS\OssClient;
use \OSS\Core\OssException;

class UploadServer {
    
    
    // 阿里云主账号AccessKey拥有所有API的访问权限，风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维，请登录RAM控制台创建RAM账号。
    private $accessKeyId = "LTAI4G2nET6QZ3k7UoZkAkmR";
    private $accessKeySecret = "nR98BeJwe5ICOcYrXctWe9ByPoBnsK";
    // Endpoint以杭州为例，其它Region请按实际情况填写。
   // private $endpoint = "http://oss-cn-guangzhou-internal.aliyuncs.com"; // 内网
    private $endpoint = "oss-cn-guangzhou.aliyuncs.com";
    // 设置存储空间名称。
    private $bucket= "images-dev";
    // 设置文件名称。
    //private $object = "<yourObjectName>";
    // <yourLocalFile>由本地文件路径加文件名包括后缀组成，例如/users/local/myfile.txt。
    // private $filePath = "<yourLocalFile>";
    
    
    public function upload(){
        $object = 'test/abc.png';
        $filePath = './uploads/advert/2019/06/04/m1/5cf5c9f7bcbf6.png';
       // dump(is_file($filePath));exit;
        try{
            $ossClient = new OssClient($this->accessKeyId, $this->accessKeySecret, $this->endpoint);
        
            $ret = $ossClient->uploadFile($this->bucket, $object, $filePath);
            dump($ret);
        }catch(OssException $e) {
            dump($e);
            printf(__FUNCTION__ . ": FAILED\n");
            printf($e->getMessage() . "\n");
            return;
        }
        print(__FUNCTION__ . ": OK" . "\n");
    }
    
    
    
}